package com.df.my_net_game.net.base;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import io.netty.handler.timeout.IdleState;
import io.netty.handler.timeout.IdleStateEvent;

import java.util.function.BiConsumer;

public class GTcpIdleHandler extends ChannelInboundHandlerAdapter {
    private GTcpServer tcpServer;
    public GTcpIdleHandler(GTcpServer tcpServer) {
        this.tcpServer = tcpServer;
    }

    @Override
    public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
        // 判断 Event 是否是 IdleStatement (用于触发用户事件, 包含 读空闲|写空闲|读写空闲)
        if (evt instanceof IdleStateEvent) {
            IdleStateEvent event = (IdleStateEvent) evt;
            if(tcpServer!=null){
                if(tcpServer.serverCB!=null){
                    tcpServer.serverCB.onDIdle(ctx,event,tcpServer);
                }
            }
//            if (event.state().equals(IdleState.READER_IDLE)) {
//                if(tcpServer!=null){
//                    if(tcpServer.serverCB!=null){}{
//                        tcpServer.serverCB.onDIdle(ctx,event,tcpServer);
//                    }
//                }
//            } else if (event.state().equals(IdleState.WRITER_IDLE)) {
//                if(tcpServer!=null){
//                    if(tcpServer.serverCB!=null){}{
//                        tcpServer.serverCB.onDIdle(ctx,event,tcpServer);
//                    }
//                }
//            } else if (event.state().equals(IdleState.ALL_IDLE)) {
//                if(tcpServer!=null){
//                    if(tcpServer.serverCB!=null){}{
//                        tcpServer.serverCB.onDIdle(ctx,event,tcpServer);
//                    }
//                }
//            }
        }
    }
}